﻿using GalaSoft.MvvmLight;
using System.Collections.ObjectModel;
using System;

namespace DiagramDesigner
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>

        private readonly Lazy<ObservableCollection<ContoursViewModel>> _appleViews;
        public MainViewModel(IDataService ids)
        {

            DataModel model = ids.GetModel();

            Func<DataSubItemModel, ContoursViewModel> viewModelCreator = subModel => new ContoursViewModel();
            Func<ObservableCollection<ContoursViewModel>> collectionCreator =
                () => new Utils.ObservableViewModelCollection<ContoursViewModel, DataSubItemModel>(model.SubItems, viewModelCreator);

            _appleViews = new Lazy<ObservableCollection<ContoursViewModel>>(collectionCreator);
        }

        public ObservableCollection<ContoursViewModel> Drops
        {
            get
            {
                return _appleViews.Value;
            }
        }



        /// <summary>
        /// The <see cref="SelectedDrop" /> property's name.
        /// </summary>
        public const string SelectedDropPropertyName = "SelectedDrop";

        private ContoursViewModel _selectedDrop = null;

        /// <summary>
        /// Sets and gets the SelectedDrop property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public ContoursViewModel SelectedDrop
        {
            get
            {
                return _selectedDrop;
            }

            set
            {
                if (_selectedDrop == value)
                {
                    return;
                }

                _selectedDrop = value;
                RaisePropertyChanged(SelectedDropPropertyName);
            }
        }
    }    

}